/**
 * @description utils api 路由
 * @author 刘煎蛋
 */

const router = require('koa-router')();
const koaFrom = require('formidable-upload-koa');
const saveFile = require('../../controller/utils');

router.prefix('/api/utils');

router.post('/upload', koaFrom(), async ( ctx, next ) => {
    const file = ctx.req.files['file'];
    
    if ( !file ) return

    const { size, name, type, path } = file;

    ctx.body = await saveFile({
        name,
        filePath:path,
        size,
        type
    })
})

module.exports = router;